﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SimpleFrameAnimation : MonoBehaviour {

    public Sprite[] sprites;
    public float interval;
    float timer;
    int index;
    Image img;
	// Use this for initialization
	void Start () {
        timer = 0f;
        index = 0;
        img = gameObject.GetComponent<Image>();
    }
	
	// Update is called once per frame
	void Update ()
    {
        timer += Time.deltaTime;
        if (timer > interval)
        {
            timer = 0;
            if (img && sprites != null)
            {
                if (index + 1 < sprites.Length)
                {
                    index++;
                }
                else
                {
                    index = 0;
                }
                img.sprite = sprites[index];
            }
        }
	}
}

